using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;

using SharpCore.Data;

namespace TF.Access {
	public partial class TF_Market {
		#region Fields
		private int iD;
		private int marketID;
		private string marketName;
		private string description;
		private string detail;
		private string imageURL;
		private int cityId;
		private int languageID;
		private string locCode;
		#endregion
		
		#region Constructors
		/// <summary>
		/// Initializes a new instance of the TF_Market class.
		/// </summary>
		public TF_Market() {
		}
		
		/// <summary>
		/// Initializes a new instance of the TF_Market class.
		/// </summary>
		public TF_Market(int marketID, string marketName, string description, string detail, string imageURL, int cityId, int languageID, string locCode) {
			this.marketID = marketID;
			this.marketName = marketName;
			this.description = description;
			this.detail = detail;
			this.imageURL = imageURL;
			this.cityId = cityId;
			this.languageID = languageID;
			this.locCode = locCode;
		}
		
		/// <summary>
		/// Initializes a new instance of the TF_Market class.
		/// </summary>
		public TF_Market(int iD, int marketID, string marketName, string description, string detail, string imageURL, int cityId, int languageID, string locCode) {
			this.iD = iD;
			this.marketID = marketID;
			this.marketName = marketName;
			this.description = description;
			this.detail = detail;
			this.imageURL = imageURL;
			this.cityId = cityId;
			this.languageID = languageID;
			this.locCode = locCode;
		}
		#endregion
		
		#region Properties
		/// <summary>
		/// Gets or sets the ID value.
		/// </summary>
		public int ID {
			get { return iD; }
			set { iD = value; }
		}
		
		/// <summary>
		/// Gets or sets the MarketID value.
		/// </summary>
		public int MarketID {
			get { return marketID; }
			set { marketID = value; }
		}
		
		/// <summary>
		/// Gets or sets the MarketName value.
		/// </summary>
		public string MarketName {
			get { return marketName; }
			set { marketName = value; }
		}
		
		/// <summary>
		/// Gets or sets the Description value.
		/// </summary>
		public string Description {
			get { return description; }
			set { description = value; }
		}
		
		/// <summary>
		/// Gets or sets the Detail value.
		/// </summary>
		public string Detail {
			get { return detail; }
			set { detail = value; }
		}
		
		/// <summary>
		/// Gets or sets the ImageURL value.
		/// </summary>
		public string ImageURL {
			get { return imageURL; }
			set { imageURL = value; }
		}
		
		/// <summary>
		/// Gets or sets the CityId value.
		/// </summary>
		public int CityId {
			get { return cityId; }
			set { cityId = value; }
		}
		
		/// <summary>
		/// Gets or sets the LanguageID value.
		/// </summary>
		public int LanguageID {
			get { return languageID; }
			set { languageID = value; }
		}
		
		/// <summary>
		/// Gets or sets the LocCode value.
		/// </summary>
		public string LocCode {
			get { return locCode; }
			set { locCode = value; }
		}
		#endregion
		
		#region Methods
		/// <summary>
		/// Saves a record to the TF_Market table.
		/// </summary>
		public void Insert() {
			iD = Convert.ToInt32(SqlClientUtility.ExecuteScalar("TF_MarketInsert", marketID, marketName, description, detail, imageURL, cityId, languageID, locCode));
		}
		
		/// <summary>
		/// Updates a record in the TF_Market table.
		/// </summary>
		public void Update() {
			SqlClientUtility.ExecuteNonQuery("TF_MarketUpdate", iD, marketID, marketName, description, detail, imageURL, cityId, languageID, locCode);
		}
		
		/// <summary>
		/// Deletes a record from the TF_Market table by its primary key.
		/// </summary>
		public void Delete() {
			SqlClientUtility.ExecuteNonQuery("TF_MarketDelete", iD);
		}
		
		/// <summary>
		/// Selects a single record from the TF_Market table.
		/// </summary>
		public static TF_Market Select(int iD) {
			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader("TF_MarketSelect", iD)) {
				if (dataReader.Read()) {
					return MakeTF_Market(dataReader);
				} else {
					return null;
				}
			}
		}
		
		/// <summary>
		/// Selects all records from the TF_Market table.
		/// </summary>
		public static List<TF_Market> SelectAll() {
			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader("TF_MarketSelectAll")) {
				List<TF_Market> tF_MarketList = new List<TF_Market>();
				while (dataReader.Read()) {
					TF_Market tF_Market = MakeTF_Market(dataReader);
					tF_MarketList.Add(tF_Market);
				}
				return tF_MarketList;
			}
		}
		
		/// <summary>
		/// Creates a new instance of the TF_Market class and populates it with data from the specified SqlDataReader.
		/// </summary>
		private static TF_Market MakeTF_Market(SqlDataReader dataReader) {
			TF_Market tF_Market = new TF_Market();
			
			if (dataReader.IsDBNull(0) == false) {
				tF_Market.ID = dataReader.GetInt32(0);
			}
			if (dataReader.IsDBNull(1) == false) {
				tF_Market.MarketID = dataReader.GetInt32(1);
			}
			if (dataReader.IsDBNull(2) == false) {
				tF_Market.MarketName = dataReader.GetString(2);
			}
			if (dataReader.IsDBNull(3) == false) {
				tF_Market.Description = dataReader.GetString(3);
			}
			if (dataReader.IsDBNull(4) == false) {
				tF_Market.Detail = dataReader.GetString(4);
			}
			if (dataReader.IsDBNull(5) == false) {
				tF_Market.ImageURL = dataReader.GetString(5);
			}
			if (dataReader.IsDBNull(6) == false) {
				tF_Market.CityId = dataReader.GetInt32(6);
			}
			if (dataReader.IsDBNull(7) == false) {
				tF_Market.LanguageID = dataReader.GetInt32(7);
			}
			if (dataReader.IsDBNull(8) == false) {
				tF_Market.LocCode = dataReader.GetString(8);
			}

			return tF_Market;
		}
		#endregion
	}
}
